﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////


#pragma once
#include "GnufBase.h"
#include <QtWidgets/QPushButton>
#include <QtCore/QAbstractNativeEventFilter>

namespace gnuf {
    class ArrangementArea;
    class IQtMaskHandler;
    class Color;

    class GNUF_BASE_EXPORT QtMask final
        : public QPushButton
        , public QAbstractNativeEventFilter
    {
    public:
        explicit QtMask(IQtMaskHandler *, const gnuf::Color &);
        void setOverall(const bool);
        bool  isOverall() const { return m_overall; }
        void appearOn(const ArrangementArea *);
        void disappear();

        enum class EQWidgetIsMasked : std::uint16_t {
            eUnfound,   // the QWidget isn't found
            eUnanswered,// the QWidget doesn't answer
            eYes,       // the QWidget wants
            eNo,        // the QWidget wants not
        };
        static QtMask::EQWidgetIsMasked askQWidgetIfMasked(const std::uint64_t winId);

    protected:
        // Inherits from QPushButton...
        virtual bool eventFilter(QObject *, QEvent *) override;
        // Inherits from QAbstractNativeEventFilter...
        virtual bool nativeEventFilter(const QByteArray &, void *, long *) override;
    private:
        void onClicked(bool);
        gcmp::WeakPtr< IQtMaskHandler > m_wpHandler;
        bool m_overall = false; // not overall, by default
#ifdef _WINDOWS
        struct OtherHwnds {
            typedef std::list< HWND > HwndList;
            std::vector< HWND > m_disabled;
            void  enable();
            void disable();
            bool collect(OtherHwnds::HwndList &) const;
        } m_otherHwnds;
#endif
    };
}
